//实现下滑
$.fn.slideDown = function(duration){
    var height = this.height();

    this.css("visibility", "visible");
    this.css("height", 0);
    this.animate({
        height: height
    }, duration);
};

$(function(){
    var giftItem = $(".gift-item");//抽奖按钮
    var deviceId = $("#deviceId").val();//设备ID
    var activeId = $("#activeId").val();//活动ID
    var first = $("#first").val();//抽奖次数

    //遮罩层
    $("html, body").css("overflow", "hidden");
    $("body").on("touchmove", function (e){
        e.preventDefault();
    });
    $("#mask").slideDown("slow");
    $("#closeBtn").on("tap", function(){
        $("#mask").hide();
        $("html, body").css("overflow", "auto");
        $("body").off("touchmove");
    });

    //拆礼盒
    giftItem.on("tap", function(){
        $.ajax({
             type: "get",
             url: "goGiftByDeviceId?deviceId="+deviceId+"&activeId="+activeId,
             dataType: "json",
             success: function(data) {
                var returnFlag = data.returnFlag;//数据是否返回成功
                var code = data.code;//活动是否开始
                 
                 //数据返回成功
                if(returnFlag){
                     //活动开始
                    if(code == "A00"){
                        window.location = "getGiftDetailPage?deviceId="+deviceId+"&first="+first;
                    }
                    if(code == "A01"){
                       alert("不要着急，活动还未开始哦！");
                    }
                    if(code == "A02"){
                       alert("您已经抽过奖了哦！");
                       window.location = "getGiftDetailPage?deviceId="+deviceId+"&first="+first;
                    }
                }
            },
            error: function(msg) {
                alert("网络超时, 数据请求失败！");
            }
        });
    });
})